﻿//===================================================================
//
// Description: Sparqube Picture Column Lite for SharePoint 2010
// Web: http://www.sparqube.com/
//
//-------------------------------------------------------------------
//
// Copyright (C) 2012 ArtfulBits.CZ (development[at]artfulbits.cz)
// Web: http://www.artfulbits.cz/
//
//-------------------------------------------------------------------
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
// PARTICULAR PURPOSE.
//===================================================================

using System.Globalization;
using System.Web;

namespace Sparqube.SharePoint.PictureColumnLite
{
	internal enum EResource
	{
		Error_NoFileUploaded,
		Error_FileIsBlockedByAdministrator,
		Error_ErrorSavingPicture,
		Error_ValueShouldBeEmptyOrPositiveInteger,
		Error_PictureStoragePathIsNotValid,
		Error_PictureStorageShouldBeSpecified,

		MAX
	}

	internal static class ResourceManager
	{
		#region Methods

		public static string GetResource(EResource resource)
		{
			return GetResource(resource, new object[0]);
		}

		public static string GetResource(EResource resource, params object[] values)
		{
			return GetResourceString("Sparqube.PictureLiteField", resource.ToString(), values);
		}

		#endregion //Methods

		#region Implementation

		private static string GetResourceString(string fileName, string strId, params object[] values)
		{
			string format = HttpContext.GetGlobalResourceObject(fileName, strId, CultureInfo.CurrentUICulture) as string;
			string text = SubstituteArgumentValues(format, values);
			if (string.IsNullOrEmpty(text))
			{
				text = strId;
			}
			return text;
		}

		private static string SubstituteArgumentValues(string format, params object[] values)
		{
			if (null != values)
			{
				for (int i = 0; i < values.Length; i++)
				{
					string oldValue = "%" + ((i + 1)).ToString(CultureInfo.InvariantCulture);
					format = format.Replace(oldValue, values[i].ToString());
				}
			}
			return format;
		}

		#endregion //Implementation

	}// ResourceManager
}
